package com.wangbloc.domain.callback;

import cn.hutool.extra.spring.SpringUtil;
import com.wangbloc.domain.service.MqttMessageService;
import com.wangbloc.domain.service.MqttService;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttMessage;

/**
 * @author wangbloc
 * @version 1.0
 * @date 2023/2/9 23:00
 **/
public class CustomMqttCallback implements MqttCallback {

    private MqttMessageService mqttMessageService = SpringUtil.getBean(MqttMessageService.class);

    private MqttService mqttService = SpringUtil.getBean(MqttService.class);

    @Override
    public void connectionLost(Throwable cause) {
        mqttService.lostAutoSubscribe();
    }

    @Override
    public void messageArrived(String topic, MqttMessage message) throws Exception {
        mqttMessageService.messageArrived(topic, message);
    }

    @Override
    public void deliveryComplete(IMqttDeliveryToken token) {

    }
}
